# -*- coding: utf-8 -*-
"""
Module Description:
Date: 2020/08/06
Author: zhongzhaopai
"""
from pyshare.utils.time_utils import getCT, isPassDay
from pyshare.const.enums.payment import UnlockType
from pyshare.const.enums.activity import ActivityType


class CrossQueenMiXin(object):

    activity_id = NotImplemented
    role_guid = NotImplemented
    cur_score = NotImplemented
    cheat_stat = NotImplemented
    grid_data = NotImplemented
    last_restart_time = NotImplemented
    vit_buy_count = NotImplemented
    vit_use = NotImplemented
    merge_record = NotImplemented
    merge_award_stat = NotImplemented
    active_value = NotImplemented

    @property
    def is_expire_data(self):
        """是否是过期数据（没有重置，一直停留在二级界面可能导致没有重置）"""
        if isPassDay(self.last_restart_time):
            return True
        return False

    def refresh_cross_queen(self, is_restart=False):
        """
        隔天重置或者重玩
        :param is_restart:
        :return:
        """
        from pyshare.dal.repository_impl import CrossQueenRoleRepository
        from app.area.component.cross.cross_queen.cross_queen_component import CrossQueenComponent

        if not isPassDay(self.last_restart_time) and not is_restart:
            # 隔天重置，判断是否隔天
            return

        self.cur_score = 0
        self.cheat_stat = {}
        self.grid_data = CrossQueenComponent.init_grid_data()
        self.last_restart_time = getCT()
        if is_restart:
            # 重玩重置数据到这里结束
            self.merge_record = {key: [val[0], 0] for key, val in self.merge_record.items()}
            self.vit_use = 0
            CrossQueenRoleRepository.save(self)
            return

        self.vit_buy_count = 0
        self.vit_use = 0
        self.merge_record = {}
        self.merge_award_stat = []
        CrossQueenRoleRepository.save(self)

    @property
    def is_unlock_special_award(self):
        """
        特殊奖励是否解锁
        :return:
        """
        from app.area.component.recharge_unlock_component import RechargeUnlockComponent
        result = RechargeUnlockComponent.check_has_recharge_unlock(self.role_guid,
                                                                   UnlockType.CrossQueenSpecialAward,
                                                                   self.activity_id)
        return 1 if result else 0

    def settle_season_second_stage(self):
        """
        结算赛季第二阶段奖励
        :return:
        """
        from pyshare.common_logic.cross_season_common import CrossSeasonCommonLogic
        CrossSeasonCommonLogic.settle_second_stage(self.activity_id,
                                                   ActivityType.CrossQueen, self.role_guid, self.active_value)

